﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using Cn.Edwon.Web.Support;
using System.Xml;
using Cn.Edwon.Web;
using Cn.Cellula.Client;

namespace Cn.Cellula.Website.Admin.Permission.Func {
    public partial class List : PageSupport {
        IUserBiz biz = BizFactory.Get<IUserBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                LoadFuncs(null);
            }
        }
        
        private void LoadFuncs(String ParentKey) {
            this.lab_UserFuncData.Text = "<script type=\"text/javascript\">var UserFuncData = " + biz.LoadFunctions2Json(this.Actor,"") + ";</script>";
        }
        protected void btn_FuncAdd_Click(object sender, EventArgs e) {
            String parms = Request.Form["cbx_function"];
            if (!String.IsNullOrEmpty(parms)) {
                String[] keys = parms.Split(',');
                Response.Redirect("Edit.aspx?pid=" + keys[0]);
            } else {
                Response.Redirect("Edit.aspx");
            }
        }

        protected void btn_FuncUpdate_Click(object sender, EventArgs e) {
            String parms = Request.Form["cbx_function"];
            if (!String.IsNullOrEmpty(parms)) {
                String[] keys = parms.Split(',');
                Response.Redirect("Edit.aspx?id=" + keys[0]);
            } else {
                SiteInfo.Send(Page, TxtDef.ERROR, TxtDef.NoEditSelect);
            }
        }

        protected void btn_FuncDel_Click(object sender, EventArgs e) {
            String parms = Request.Form["cbx_function"];
            if (!String.IsNullOrEmpty(parms)) {
                String[] keys = parms.Split(',');
                try {
                    biz.DeleteFunctions(keys);
                    BizFactory.Get<ILogBiz>().LogDelete("功能", keys.Length, this.Actor, Request);
                } catch(Exception ex) {
                    SiteInfo.Send(Page, TxtDef.ERROR, ex.Message);
                }
                this.LoadFuncs(null);
            } else {
                SiteInfo.Send(Page, TxtDef.ERROR, TxtDef.NoDelSelect);
            }
        }
    }
}
